var setting_industry = {
	check : {
		enable : true,
		chkboxType : {
			"Y" : "ps",
			"N" : "ps"
		}
	},
	data : {
		simpleData : {
			enable : true
		}
	}
};
var setting_region = {
	check : {
		enable : true,
		chkboxType : {
			"Y" : "",
			"N" : ""
		}
	},
	data : {
		simpleData : {
			enable : true
		}
	}
};
function onSave() {
			treeObj = $.fn.zTree.getZTreeObj("treeIndustry");
			nodes = treeObj.getCheckedNodes(true);
			nodesValue = "";
			var num = 0;
			for (var i = 0; i < nodes.length; i++) {
				if (nodes[i].isParent == true)
					continue;
				if (i == nodes.length - 1) {
					nodesValue += nodes[i].id;
				} else {
					nodesValue += nodes[i].id + ",";
				}
			}
				$("#industry_value").attr("value", nodesValue);
		
			treeObj = $.fn.zTree.getZTreeObj("treeRegion");
			nodes = treeObj.getCheckedNodes(true);
			nodesValue = "";
			var num1=0;
			for (var i = 0; i < nodes.length; i++) {
				if (i == nodes.length - 1) {
					nodesValue += nodes[i].id;
				} else {
					nodesValue += nodes[i].id + ",";
				}
			}
			$("#region_value").attr("value", nodesValue);
			
			$("#save").click();	
}
$(document).ready(function() {
	// 首先展示整个的地区
	$.getJSON('./json-journalist-getallregions?json_language='
					+ $("input[name=\"json_language\"]").attr("value"),
			function(zNodesRegion0) {
					$.fn.zTree.init($("#treeRegion"), setting_region,
							zNodesRegion0);
							region_fill($("input[name=\"regionattr\"]").attr("value"));
			});
	// 首先展示整个的行业
	$.ajax({
				url : './json-journalist-getallindustries?json_language='
						+ $("input[name=\"json_language\"]").attr("value"),
				success : function(zNodesIndustry0) {
					$.fn.zTree.init($("#treeIndustry"),
							setting_industry, zNodesIndustry0);
						industry_fill($("input[name=\"industryattr\"]").attr("value"));	
				},
				dataType : "json"
			});
});

function deal() {
				// 填写行业
				//industry_fill($("input[name=\"industryattr\"]").attr("value"));
				// 填写地区
				//region_fill($("input[name=\"regionattr\"]").attr("value"));
}

// 选中并且打开地区
function region_fill(dataSelected) {
		var treeObj = $.fn.zTree.getZTreeObj("treeRegion");
		if(dataSelected!=""){
			dataSelected = $.parseJSON(dataSelected);
			for (x in dataSelected) {
				var node = treeObj.getNodeByParam("id", dataSelected[x],
						null);
				treeObj.checkNode(node, true, true);
				treeObj.selectNode(node);
			}
			window.scrollTo(0,0);
		}
	}

// 选中并且打开行业
function industry_fill(dataSelected) {
		var treeObj = $.fn.zTree.getZTreeObj("treeIndustry");
		var nodes = treeObj.getSelectedNodes();
		if(dataSelected!=""){
			dataSelected = $.parseJSON(dataSelected);
				for (x in dataSelected) {
					var node = treeObj.getNodeByParam("id", dataSelected[x],
							null);
					treeObj.checkNode(node, true, true);
					treeObj.selectNode(node);
				}
		window.scrollTo(0,0);
		}
	}


	function onAddStock(){
		$("input[id='addStock']").before($("#stockmodel").html());
	}
		function onAddCompany(){
		$("input[id='addCompany']").before($("#companymodel").html());
	}
	